#ifndef DBTABSETTINGS_H
#define DBTABSETTINGS_H

#include <QString>
#include <QSqlDatabase>
#include <QDebug>
#include <QMap>

#include <QSqlDatabase>
#include <QSqlError>

class DBTabSettings
{
public:
    static const QString SETTING_DB_NAME;

    static const QString _KEY;
    static const QString _VALUE;

    static DBTabSettings* getObj(const QString &tabName){
        if(mDBMap.contains(tabName)){
            return mDBMap.value(tabName);
        }else{

            if(mDb.isValid()==false){
                mDb = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"),QLatin1String("settings"));
                mDb.setDatabaseName(SETTING_DB_NAME);
                if(!mDb.open()){
                    exit(-1);
                }
            }
            DBTabSettings *obj = new DBTabSettings(tabName);
            mDBMap.insert(tabName,obj);
            //mDBMap.insert(tabName,obj);
            return obj;
        }
    }


    QVariant getValue(const QString &key,const QVariant &def="");
    void setValue(const QString &key,const QVariant &value);
    int getMaxIndex(const QString &key);
private:
    void createTab(void);
    DBTabSettings(const QString &tabName);
    const QString mTabName;

    static QMap<QString,DBTabSettings*> mDBMap;
    static QSqlDatabase mDb;

};

#endif // DBTABSETTINGS_H
